package com.chalk.util;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;

public class JAXBUtil {



    public static <T> T convertToJavaBean(Class<T> clz, String xml) {
        try {
            JAXBContext jaxbContext = JAXBContext.newInstance(clz);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            T t = (T) unmarshaller.unmarshal(new StringReader(xml));
            return t;
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return null;
    }
}
